package com.wali.modules.common.control;

import com.wali.common.ccp.exception.CcpException;
import com.wali.common.enums.ErrorCodeEnum;
import com.wali.common.web.BaseController;
import com.wali.modules.common.service.ComChannelService;
import com.wali.modules.common.vo.ComChannelVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author walixu
 * @ClassName com.wali.modules.common.control
 * @Description 渠道controller类
 * @email wali.xu@kpmg.com
 * @date 24/01/2019 7:43 下午
 */
@Controller
@RequestMapping(value = "/com")
public class ComChannelController extends BaseController {

    @Autowired
    private ComChannelService comChannelService;

    /**
     * @param
     * @return
     * @throws
     * @Title listAllComChannel
     * @Description 查询所有的渠道信息
     */
    @RequestMapping(value = "/listAllComChannel", method = RequestMethod.GET)
    public ResponseEntity<String> listAllComChannel() {
        int code = ErrorCodeEnum.ERROR_INTERNAL_CODE.getCode();
        String msg = ErrorCodeEnum.ERROR_INTERNAL_CODE.getMessage();

        try {
            List<ComChannelVO> comChannelList = comChannelService.listAllComChannel();

            code = ErrorCodeEnum.SUCCESS_CODE.getCode();
            msg = ErrorCodeEnum.SUCCESS_CODE.getMessage();
            return getResponseEntity(code, msg, comChannelList);
        } catch (CcpException e) {
            logger.error(e.getMessage(), e);
            code = e.getException().getCode();
            msg = e.getException().getMessage();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

        return getResponseEntity(code, msg);
    }


}
